package cn.iocoder.yudao.module.member.vip.mq;

import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.module.api.member.vip.message.VipOrderPaidMessage;
import cn.iocoder.yudao.module.api.member.vip.message.VipUserExpiredMessage;
import cn.iocoder.yudao.module.api.member.vip.vo.VipOrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 会员 事件生产者
 *
 * @author 山野羡民
 */
@Component
@Slf4j
public class VipProducer {

    /**
     * 发送 {@link VipOrderPaidMessage} 消息
     *
     * @param order 交易订单信息
     */
    public void sendVipOrderPaidMessage(VipOrderVO order) {
        log.info("[sendVipOrderPaidMessage] {}", order);
        SpringUtil.getApplicationContext().publishEvent(new VipOrderPaidMessage(order));
    }

    /**
     * 发送 {@link VipUserExpiredMessage} 消息
     *
     * @param userId 用户编号
     */
    public void sendVipUserExpiredMessage(Long userId) {
        log.info("[sendVipUserExpiredMessage] {}", userId);
        SpringUtil.getApplicationContext().publishEvent(new VipUserExpiredMessage(userId));
    }

}
